package org.yaac.server.service;

import java.util.logging.Logger;

import javax.inject.Inject;

import org.yaac.client.service.ChannelClientService;

import com.google.appengine.api.channel.ChannelServiceFactory;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserServiceFactory;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
public class ChannelClientServiceImpl implements ChannelClientService {

	private final Logger logger;
	
	@Inject
	ChannelClientServiceImpl(Logger logger) {
		super();
		this.logger = logger;
	}

	@Override
	public String requestChannelToken() {
		User currUser = UserServiceFactory.getUserService().getCurrentUser();
		logger.info(currUser + " requests to open a new channel");
		
		String currEmail = UserServiceFactory.getUserService().getCurrentUser().getEmail();
		String token = ChannelServiceFactory.getChannelService().createChannel(currEmail);
		
		logger.info("Channel : " + token + " is opened for user " + currEmail);
		
		return token;
	}
}
